<html>
<head>
    <meta charset="utf-8">
<#assign base=request.contextPath  />
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <title>套餐表</title>
    <script type="text/javascript" src="${base}/js/zhang.js"></script>
    <script src="${base}/js/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
    <script src="${base}/js/jquery.min.js"></script>

    <link rel="stylesheet" href="${base}/js/layui/css/layui.css?t=1534970980648" media="all">


    <style type="text/css">
        form {
            padding: 20px;
        }

        .layui-btn-radius {
            border-radius: 5px;
        }
    </style>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>套餐信息</legend>
</fieldset>
<div class="demoTable" style="padding:15px;">
    <button class="layui-btn layui-btn-radius" id="btn2" data-method="offset" type="button"
            style="background-color: #0092EF;">添加套餐
    </button>
    <div class="layui-inline layui-form" style="float:right;">
        <div class="layui-input-inline">
            <select name="modules" lay-verify="required" id="sech" lay-search="">
                <option value="">请选择要搜索的列</option>
                <option value="meal_name">套餐名</option>
                <option value="meal_price">套餐价格</option>
            </select>
        </div>
        <div class="layui-inline">
            <input class="layui-input" name="id" id="demoReload" autocomplete="off">
        </div>
        <button class="layui-btn layui-btn-radius" id="btn1" data-type="reload" style="background-color: #0092EF;">搜索
        </button>
    </div>
</div>
<table class="layui-hide" id="table_user" lay-filter="user"></table>
<#--<script type="text/html" id="barDemos">
    <button class="layui-btn layui-btn-sm layui-btn-normal" onclick="selectmother('{{d.id}}')" id="selectmother">详细信息</button>
</script>-->
<script type="text/html" id="barDemo">
    <#--放大镜-->
<#--    <i class="layui-icon layui-icon-search" lay-event="edit" id="updatemother"
       style="font-size: 20px;"></i>&nbsp;&nbsp;&nbsp;-->
<#--编辑-->
<i class="layui-icon layui-icon-edit" lay-event="edit" id="updatemother"
       style="font-size: 20px;"></i>&nbsp;&nbsp;&nbsp;



    <i class="layui-icon layui-icon-delete layui-btn-xs" lay-event="del" id="delectmother" href="javascript:void(0)"
       onclick="delectMeal('{{d.id}}')" style="font-size: 20px;"></i>
</script>

<script>
    layui.use(['form', 'layedit', 'laydate', 'table'], function () {
        var form = layui.form
                , $ = layui.jquery
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate
        table = layui.table;
        //方法级渲染
        table.render({
            elem: '#table_user'
            , url: '${base}/trMeal/selectMeal'//数据接口
            , toolbar: '#toolbarDemo'
            , defaultToolbar: ['filter', 'print', 'exports']
            , cols: [[
                {
                    field: 'id', templet: function (val) {
                        return val.LAY_INDEX
                    }, title: 'ID', align: 'center', width: 60, fixed: true
                }
                , {field: 'mealName', title: '套餐名', align: 'center'}
                , {field: 'mealPrice', title: '套餐价格', align: 'center'}
                //, {field: 'mealText', title: '套餐明细', align: 'center', width: 120}
                ,
                {field: 'createTime', templet: function (val) {
                        return DateFormat(val.createTime);
                    }, title: '日期时间', align: 'center'}
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150, align: 'center'}
            ]]
            , id: 'testReload'
            , page: {
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                , theme: '#0092EF'
                , limit: 20
            }, done: function (res, curr, count) {
                this.where = {};
            }
            , height: 500
        });
        var active = {
            offset: function (othis) {
                var type = othis.data('type')
                        , text = othis.text();
                layer.open({
                    type: 2,
                    title: '添加套餐',
                    shadeClose: false,
                    area: ['420px', '260px'],
                    content: '${base}/trMeal/mealAdd',
                    success: function (layero, index) {
                        var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();

                    }
                });
            }
        };
        $('#btn2').on('click', function () {
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });

        layui.form.on('select()', function (data) {
            $("#demoReload").val("")
        });

        //编辑弹出层(修改套餐)
        table.on('tool(user)', function(obj){
            var layEvent = obj.event;
            if(layEvent=="edit"){
                var data = obj.data;
                //示范一个公告层
                layer.open({
                    type: 2,
                    title: '编辑套餐信息',
                    shadeClose:false ,
                    area: ['420px', '260px'],
                    content: '${base}/trMeal/meal_edit',
                    success: function (layero, index) {
                        //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        var iframeWin = window[layero.find('iframe')[0]['name']];
                        iframeWin.$("#mealName").val(data.mealName);
                        iframeWin.$("#mealPrice").val(data.mealPrice);
                        iframeWin.$("#id").val(data.id)

                        //渲染一下form表单
                        iframeWin.layui.form.render('select');
                        iframeWin.layui.form.render();
                    }
                });
            }

        });
    });



    //删除
    function delectMeal(id) {
        layer.confirm('真的要删除吗?', function (index) {
            $.ajax({
                type: "POST",
                url: "${base}/trMeal/deleteMeal",
                data: {"id": id},
                success: function (data) {
                    var table = layui.table;
                    //表刷新方法
                    table.reload('testReload', {
                        url: '${base}/trMeal/selectMeal'
                        , where: {} //设定异步数据接口的额外参数
                    });
                    layer.close(index);
                }
            });

        });
    }
    $('#btn1').on('click', function () {
        var sechLin = $("#sech").val();
        var sechData = $("#demoReload").val();
        var whereData = {};
        whereData.lin = sechLin;
        whereData.data = Trim(sechData);
        whereData.page = 1;
        whereData.limt = 10;

        var table = layui.table;
        //表刷新方法
        table.reload('testReload', {
            url: '${base}/trMeal/list'
            , where: whereData //设定异步数据接口的额外参数
        });
    });
    //键盘事件
    $("body").bind("keydown", function (e) {
        // 兼容FF和IE和Opera
        var theEvent = e || window.event;
        var code = theEvent.keyCode || theEvent.which || theEvent.charCode;
        if (code == 13) {
            //回车执行查询
            $("#btn1").click();
        }
    });
</script>

</body>
</html>